package com.ai.ly.goodsautocat.autocat;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.ai.ly.goodsautocat.vo.SampleVO;

import de.bwaldvogel.liblinear.FeatureNode;

public class FeatureNodeBuilder {
	
	public static FeatureNode[] buildSvmNodes(SampleVO sample) {
		Map<Integer, Integer> indexCountMap = sample.getIndecCountMap();

		// FeatureNode的index要从小到大排序
		FeatureNode[] nodeArr = new FeatureNode[indexCountMap.size()];

		int i = 0;
		Set<Integer> keySet = indexCountMap.keySet();
		Iterator<Integer> iter = keySet.iterator();
		while (iter.hasNext()) {
			int index = iter.next();
			int value = indexCountMap.get(index);

			FeatureNode node = new FeatureNode(index, value);
			nodeArr[i] = node;
			i++;
		}
		return nodeArr;
	}
	
}
